/*反馈建议
彭济
9-24*/
import BasicController from './../BasicController'
import ErrorHandlerCode from './../../util/ErrorHandlerCode'
import {FeedBackModel} from '../../model'

class FeedbackController extends BasicController{
	insertFeedback(req,res,next){
		if(!super.isEmptyParameter(req.body.content)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'content 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.contact)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'contact 为必填参数'
            })
            return;
		}
		if(!super.isEmptyParameter(req.body.contact)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'contact 为必填参数'
            })
            return;
		}
		req.body.feedback_time = new Date();
		req.body.is_view = 0;
		FeedBackModel.insertFeedback(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackPaging(req,res,next){
		if(!super.isEmptyParameter(req.body.page_size)){
			req.body.page_size = 10;
		}
		if(!super.isEmptyParameter(req.body.page_no)){
			req.body.page_no = 1;
		}
		FeedBackModel.feedbackListpage(req.body).then((data) =>{
            super.RequestSuccessMsg(res, data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackDelById(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
		}
		FeedbackModel.delFeedback(req.body.id).then((data) =>{
            super.RequestSuccessMsg(res,data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackUpdate(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
		}
		FeedbackModel.updateFeedBack(req.body).then((data) =>{
            super.RequestSuccessMsg(res,data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackDel(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
		}
		FeedbackModel.delFeedback(req.body).then((data) =>{
            super.RequestSuccessMsg(res,data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackFindAll(req,res,next){
		FeedbackModel.feedbackFindAll().then((data) =>{
            super.RequestSuccessMsg(res,data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
	feedbackFindById(req,res,next){
		if(!super.isEmptyParameter(req.body.id)){
			res.json({
                code:ErrorHandlerCode.MISSINGPARAMETER,
                message: 'id 为必填参数'
            })
            return;
		}
		FeedbackModel.feedbackFindAll(req.body.id).then((data) =>{
            super.RequestSuccessMsg(res,data);
        }).catch((err) => {
            res.json(ErrorHandlerCode.INNERSERVICERROR);
            throw err;
        })
	}
}
module.exports = new FeedbackController();